<?php
    
    include 'database.php';
    //include 'public.php';
    
    // header('Content-Type:text/html; charset=utf8');
    // print_r( getContentPre(16, "1234") );
    
    
    function getContent($tempId){
        $db = new Database();
        $data = array("id"=>0, "content"=>"", "status"=>1, "message"=>"不存在");
        $sql = "select id, content, createTime, title, code, category, timeLength, passwd from article where tempId=?";
        
        $rst = $db->SelectEx($sql, array($tempId));
        if(count($rst)==0) return $data;
        $d = $rst[0];
        $data['id'] = $d['id'];
        $data['content'] = htmlspecialchars_decode($d['content']);
        $data['createTime'] = $d['createTime'];
        $data['message'] = "success";
        $data['status'] = 0;
        
        $data['setting'] = array("title"=>$d['title'], "code"=>$d['code'], 
            "category"=>$d['category'], "time"=>$d['timeLength'], "passwd"=>$d['passwd']);
        return $data;
    }
    
    function getContentPre($tempId, $passwd=null){
        $db = new Database();
        $data = array("id"=>0, "content"=>"", "status"=>1, "message"=>"不存在");
        $sql = "select id,  passwd from article where tempId=?";
        
        $rst = $db->SelectEx($sql, array($tempId));
        if(count($rst)==0) return $data;
        if($rst[0]['passwd']!=null){
            if($passwd==null){
                $data['status'] = 2;
                $data['message'] = "缺少密码";
                return $data;
            }else if($passwd!=$rst[0]['passwd']){
                $data['status'] = 3;
                $data['message'] = "密码错误";
                return $data;
            }
        }
        return getContent($tempId);
    }



?>